package com.tianhao.luo.graph;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author tianhao.luo
 * @date 2019/12/19 10:23
 */
public class RectangleFactory implements GraphFactory {
    private  HashMap<Integer, List<Line>> hashMap ;
    private Rectangle rectangle;
    /**
     * 构造图形
     *
     * @param sides 长和宽
     * @return 矩形
     */
    @Override
    public Graph create(int[] sides) {
        hashMap = new HashMap<>(4);
        int length = sides[0];
        int height = sides[1];
        ArrayList<Line> lines = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            //奇数边，为长
            if (0!=i/2) {
                Line line = new Line(length);
                lines.add(line);
            }else {
                Line line = new Line(height);
                lines.add(line);
            }
        }
        hashMap.put(4,lines);
        rectangle = new Rectangle(hashMap);
        return rectangle;
    }
}
